package com.kc.gb.device.plugins.strip.controller;


import com.kc.gb.base.dto.Result;
import com.kc.gb.device.plugins.strip.service.StripHardwareService;
import com.kc.gb.feign.strip.sopport.dto.StripCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;


/**
 * 灯带测试controller
 */
@RestController
@RequestMapping("/station/device/strip/")
@Slf4j
public class StripHardwareController {

    @Resource
    private StripHardwareService deviceStripService;

    @PostMapping("/commands")
    Result<?> commands(@RequestBody List<StripCommand> commands) {
        // 硬件设备直接调用默认使用模拟器模式
        AtomicBoolean DEBUG_MODE = new AtomicBoolean(false);
        deviceStripService.consumeCommands(commands,DEBUG_MODE.get());
        return Result.success();
    }

    /**
     * 打开指定灯珠
     * @param index
     */
    @GetMapping("/open")
    public void open(@RequestParam Integer index){
        deviceStripService.openLight(false,Arrays.asList(index));
    }

    /**
     * 关闭指定灯珠
     * @param index
     */
    @GetMapping("/close")
    public void close(@RequestParam Integer index){
        deviceStripService.closeLight(false,Arrays.asList(index));
    }
}
